package lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * @author Summerday
 */
public class PredicateTest {

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7));

        List<Integer> result = getByExample(list, num -> num % 2 == 0);

        result.forEach(System.out::println);

    }

    private static List<Integer> getByExample(List<Integer> list, Predicate<Integer> condition) {

        List<Integer> res = new ArrayList<>();
        for (Integer num : list) {
            if (condition.test(num)) {
                res.add(num);
            }
        }
        return res;
    }
}
